﻿using Iworld.Backstage.Framework.AdministratorService;
using Iworld.Backstage.Framework.GameService;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Backstage.Framework
{
    /// <summary>
    /// 个人抽水统计视图模型
    /// </summary>
    public class ProfitStatisticsOfPersonViewModel : ShowListViewModelBase<ProfitStatisticsOfPersonExport, GameServiceClient>
    {
        string keyword = null;
        /// <summary>
        /// 关键字
        /// </summary>
        public string Keyword
        {
            get
            {
                return keyword;
            }
            set
            {
                if (keyword != value)
                {
                    keyword = value;
                    OnPropertyChanged("Keyword");
                    Refresh(1);
                }
            }
        }
        
        public ProfitStatisticsOfPersonViewModel()
            : base(PageCategory.数据报表.ToString(), Page.个人抽水统计.ToString())
        {
            client.GetProfitStatisticsOfPersonCompleted += this.WrapEventHandler<GetProfitStatisticsOfPersonCompletedEventArgs>(GetProfitStatisticsCompleted);
        }

        void GetProfitStatisticsCompleted(object sender, GetProfitStatisticsOfPersonCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                this.PageIndex = e.Result.PageIndex;
                this.TotalPage = e.Result.CountOfPage;
                UpdateLsit(e.Result.List);
            }
            else
            {
                ShowError(e.Result.Error);
            }
        }

        protected override void Refresh(object obj)
        {
            int pageIndex = obj == null ? this.PageIndex : Convert.ToInt32(obj);
            client.GetProfitStatisticsOfPersonAsync(new GetProfitStatisticsOfPersonImport()
            {    
                PageIndex = pageIndex,
                Keyword=this.keyword,
                Token = DataManager.GetValue<AdministratorExport>(DataKey.Administrator_Info).Token
            });
        }

        protected override void Reset(object obj)
        {
            Keyword = null;
            this.PageIndex = 1;
            Refresh(null);
        }
    } 
}
